<template>
  <div class="userList">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="88px">
      <el-form-item label="用户级别" prop="userType">
        <el-select v-model="queryParams.userType" clearable>
          <el-option
            v-for="item in userTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单类型" prop="terminalName">
        <el-select v-model="queryParams.payMethod" clearable>
          <el-option
            v-for="item in orderTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单时间">
         <el-date-picker
            v-model="dateRange"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetQuery">重置</el-button>
        <el-button type="primary" @click="handleQuery">查询</el-button>
      </el-form-item>
    </el-form>
    <el-form>
      <el-button  size="small" type="primary" @click="handleExport">导出</el-button>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
      style="width: 100%;margin-top:16px"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="50"></el-table-column>
      <el-table-column label="序号" width="60">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单号" prop="orderNo" />
      <el-table-column label="手机号" prop="phone" />
      <el-table-column label="用户级别" prop="userType" />
      <el-table-column label="用户余额" prop="balance" />
      <el-table-column label="所属代理商">
        <template slot-scope="scope">
          {{scope.row.nickName ? scope.row.nickName : '无'}}
        </template>
      </el-table-column>
      <el-table-column label="所属门店">
        <template slot-scope="scope">
          {{scope.row.storeName ? scope.row.storeName : '无'}}
        </template>
      </el-table-column>
      <el-table-column label="所属车队">
        <template slot-scope="scope">
          {{scope.row.fleetName ? scope.row.fleetName : '无'}}
        </template>
      </el-table-column>
      <el-table-column label="订单类型" prop="payMethod" />
      <el-table-column label="订单金额">
        <template slot-scope="scope">
          {{scope.row.amount ? Number(scope.row.amount).toFixed(2) : '0'}}
        </template>
      </el-table-column>
      <el-table-column label="注册时间" prop="createdTime" />
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { getOrderStatList } from "@/api/common";

export default {
  name: "Online",
  data() {
    return {
      dateRange:[],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        params:{}
      },
      userTypeList:[
        {value:'1',label:'会员'},
        {value:'0',label:'非会员'},
      ],
      orderTypeList:[
        {value:'1',label:'加注'},
        {value:'0',label:'充值'},
      ],
      dealShow:false,
      dealItem:{},
      checked1:false,
      checked2:false,
      addNum:null,
      selection:[]
    };
  },
  created() {
    this.getList();
  },
  watch:{
    dateRange(val){
      console.log(val)
      if(val){
        this.queryParams.params.startDate = val[0]
        this.queryParams.params.endDate = val[1]
      }else{
        this.queryParams.params = {}
      }
    }
  },
  methods: {
    getList() {
      this.loading = true;
      getOrderStatList(this.queryParams).then(response => {
        this.list = response.rows
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams =  {
        pageNum: 1,
        pageSize: 10,
        params:{}
      }
      this.dateRange = []
      this.handleQuery();
    },
    handleExport() {
      this.download('/order/statisticsListExport', {
        // ...this.queryParams
      }, `订单统计_${new Date().getTime()}.xlsx`)
    },
    handleSelectionChange(val){
      this.selection = val
      console.log(val);
    }
  }
};
</script>

<style lang="scss" scoped>
.userList{
  margin-top: 20px;
}
</style>

